<template>
    <div class="heard">
        <div class="w">
            <div class="search-nav flex-row">
                <!-- logo -->
                <a href="#" class="logo">
                    <img src="@/assets/img/logo.png" />
                </a>
                <!-- 搜索框 -->
                <div class="search-box">
                    <div class="search-bar">
                        <form @submit.prevent="searchMethod">
                            <input type="text" v-model="keyword" placeholder="请输入商品名称" />
                            <button native-type="submit">
                                <el-icon><Search /></el-icon>
                            </button>
                        </form>
                    </div>
                    <div class="nav-link" v-if="props.adList !== ''">
                        <ul>
                            <li v-for="(item, index) in props.adList" :key="index">
                                <a :href="item.url">{{ item.string }}</a>
                            </li>
                        </ul>
                    </div>
                </div>
                <!-- 购物车商品数量 -->
                <div class="shop-car">
                    <!-- data-pronum商品数量,传递给元素展示  -->
                    <el-icon class="svg" data-pronum="7"><ShoppingCart /></el-icon>
                    <span>我的购物车</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { List, Search, ShoppingCart } from '@element-plus/icons-vue';
import { ref } from 'vue';
import router from '@/router/index';

let keyword = ref('');
const props = defineProps({
    keyword: {
        type: String,
        default: '',
    },
    adList: {
        type: List,
        default: [''],
    },
});

const searchMethod = () => {
    if (keyword.value === '') {
        ElMessage.error('请输入搜索内容');
        return;
    }
    router.push({ path: '/search', query: { text: keyword.value } });
};
</script>

<style lang="scss" scoped>
.heard {
    background-color: #fff;
}
.search-nav {
    background-color: #fff;
    align-items: center;
    justify-content: space-between;
}

.logo {
    > img {
        width: 180px;
        height: 85px;
    }
}

.search-bar > form {
    position: relative;
    width: 550px;
    height: 36px;
    background-color: $blue1;
    border: 2px solid $blue1;
}
.search-bar > form > input {
    padding: 0;
    width: 488px;
    height: 32px;
    text-indent: 4px;
    border: 1px solid transparent;
    padding: 1px;
    outline: none;
    font-size: 14px;
    &::placeholder {
        // color: #e5e5e5;
        font-size: 14px;
        letter-spacing: 1px;
    }
    &:focus {
        &::placeholder {
            color: #ffffff;
        }
    }
}
.search-bar > form > button {
    float: right;
    width: 58px;
    height: 40px;
    color: #e5e5e5;
    font-size: 24px;
    border: none;
    background-color: transparent;
    vertical-align: baseline;
}
.search-bar button {
    &:hover {
        cursor: pointer;
    }
}
.nav-link {
    margin-top: -8px;
}
.nav-link > ul {
    padding-left: 0;
    > li {
        padding-right: 12px;
        padding-left: 5px;
        float: left;
        > a:hover {
            color: $blue4;
        }
    }
}
.shop-car {
    margin-right: 24px;
    width: 132px;
    height: 36px;
    font-size: 14px;
    overflow: hidden;
    text-align: center;
    line-height: 40px;
    border: 1px solid $blue1;
    span {
        vertical-align: 4px;
    }
    .svg {
        font-size: 18px;
        // margin: 0 8px;
        margin-left: 4px;
        margin-right: 16px;
        position: relative;
        &::before {
            // 自定义属性 商品数量
            content: attr(data-pronum);
            font-size: 12px;
            position: absolute;
            right: -80%;
            top: -50%;
            color: #fff;
            font-weight: 500;
            width: 22px;
            text-align: center;
            // text-indent: ;
            border-radius: 8px;
            background-color: $blue1;
            transform: scale(0.8);
        }
    }
}
</style>
